fix(hubspot): classify persistent 401-after-token-refresh as non-retryable - #91329
Merged
Merged
Conversation
…yable
helpers._get raises HubspotRetryableError("Hubspot API 401 - refreshed token, retrying: url=...")
after each 401 response, refreshing the access token and signalling tenacity to retry. After 5
retries all returning 401, tenacity re-raises that exception. No existing non-retryable pattern
matched this message format, so the error surfaced in error tracking and kept triggering Temporal
activity retries instead of stopping with an actionable reconnect message.
Add "Hubspot API 401 - refreshed token, retrying:" to get_non_retryable_errors() and extend the
test_unauthorized_error_is_non_retryable parametrized test with the exact message format observed
in the live event.
Generated-By: PostHog Desktop
Task-Id: 536b4fc5-280a-4665-98cd-3d612a5cca71
|
😎 Merged successfully - details. |
Contributor
|
Hey @Gilbert09! 👋 It looks like your git author email on this PR isn't your
You can fix it for this repo with: git config user.email "you@posthog.com"Or set it globally with |
Contributor
🤖 CI report
|
There was a problem hiding this comment.
Small, well-tested error-classification fix by an author on the owning team; no schema, API, auth-bypass, or dependency risk.
- Author wrote 0% of the modified lines and has 5 merged PRs in these paths (familiarity MODERATE).
Gate mechanics and policy version
| Gate | Result | |
|---|---|---|
| prerequisites | ✓ | all clear |
| deny-list | ✓ | no deny categories matched |
| size | ✓ | 12L, 1F substantive, 18L/2F incl. docs/generated/snapshots — within ceiling |
| tier | ✓ | T1-agent / T1a-trivial (18L, 2F, single-area, fix) |
| stamphog 2.0.0b4 | .stamphog/policy.yml @ 39dd204 · reviewed head 39dd204 |
Contributor
|
/trunk merge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A HubSpot sync whose OAuth credentials have been revoked or expired keeps triggering Temporal activity retries instead of stopping with an actionable message. The sync surfaces in error tracking as an unhandled `HubspotRetryableError` rather than resolving to a clear "reconnect your account" failure.
`helpers._get` raises `HubspotRetryableError("Hubspot API 401 - refreshed token, retrying: url=...")` after each 401 response — it refreshes the access token and signals tenacity to retry. After 5 retries all returning 401, tenacity re-raises that exception. The existing non-retryable pattern `"401 Client Error: Unauthorized"` matches the format from `requests.raise_for_status()`, but the `if r.status_code == 401:` branch fires before `raise_for_status()` runs, so that path is never reached for a 401. No existing pattern matches the actual re-raised message.
Error tracking issue: https://us.posthog.com/project/2/error_tracking/01a05016-5d19-7a01-b5f2-d6d2690c920b
Changes
How did you test this code?
Two new parametrized cases added to `test_unauthorized_error_is_non_retryable` — the exact message observed in the live error event, and a second endpoint variant. These catch a regression where the pattern is removed or the prefix is changed without a matching test update.
All 146 tests in `test_source_routing.py` pass. Database-backed and ClickHouse-backed suites were not run (not required for this change).
Automatic notifications
Docs update
None — no user-facing docs cover internal error classification.
🤖 Agent context
Autonomy: Fully autonomous
Generated by PostHog Desktop. Skills invoked: `/writing-pr-descriptions`, `/writing-tests`. Investigation confirmed the error originates in `helpers.py:182` inside `_get()` (within `fetch_data()`), which raises `HubspotRetryableError` with a distinct message format. The fix adds the actual surfaced pattern. No duplicate PRs were found addressing this error in the hubspot source.
Created with PostHog Desktop